{% extends "base.html" %}

{% block title %}查看脚本版本 - {{ script.name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">
                        {{ script.name }} - 版本 {{ version.version }}
                        <small class="text-muted">
                            由 {{ version.created_by }} 创建于 {{ version.created_at.strftime('%Y-%m-%d %H:%M:%S') }}
                        </small>
                    </h5>
                </div>
                <div class="card-body">
                    <div class="mb-3">
                        <label class="form-label">提交信息</label>
                        <p class="form-control-plaintext">{{ version.commit_message }}</p>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">脚本内容</label>
                        <pre><code class="language-python">{{ version.content }}</code></pre>
                    </div>
                    
                    <div class="mb-3">
                        <form action="{{ url_for('rollback_script_version', script_id=script.id, version=version.version) }}" method="post" style="display: inline;">
                            <button type="submit" class="btn btn-warning" onclick="return confirm('确定要回滚到此版本吗？')">
                                <i class="fas fa-history"></i> 回滚到此版本
                            </button>
                        </form>
                        <a href="{{ url_for('edit_script', script_id=script.id) }}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> 返回编辑
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    // 代码高亮
    document.addEventListener('DOMContentLoaded', (event) => {
        document.querySelectorAll('pre code').forEach((block) => {
            hljs.highlightBlock(block);
        });
    });
</script>
{% endblock %}